package com.genghis.rapidcrm.kernel.model;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author xulixin
 */
public abstract class RapidBaseModel {

    protected Map<String, Object> valueMap;

    public RapidBaseModel() {
        this(new HashMap<>());
    }

    /**
     * Constructor
     * @param values Array
     */
    public RapidBaseModel(Map<String, Object> values) {
        this.valueMap = values;
    }

    /**
     * Function to get the value for a given key
     * @param key
     * @return Value for the given key
     */
    public Object get(String key){
        return this.valueMap.get(key);
    }

    public boolean getForSql(String key) {
        return this.getForSql(key, true);
    }

    /**
     * Function to get the value if its safe to use for SQL Query (column).
     * @param key <String>
     * @param skipEmpty <Boolean> - Skip the check if string is empty
     * @return Value for the given key
     */
    public boolean getForSql(String key, boolean skipEmpty) {
        // return Vtiger_Util_Helper.validateStringForSql(this.get(key), skipEmpty);
        return false;
    }

    /**
     * Function to set the value for a given key
     * @param key <String>
     * @param value <Object>
     * @return Vtiger_Base_Model
     */
    public void set(String key , Object value){
        this.valueMap.put(key, value);
    }

    /**
     * Function to set all the values for the Object
     * @param values Array (key-value mapping)
     * @return Vtiger_Base_Model
     */
    public void setData(Map<String, Object> values){
        this.valueMap = values;
    }

    /**
     * Function to get all the values of the Object
     * @return Array (key-value mapping)
     */
    public Map<String, Object> getData(){
        return this.valueMap;
    }

    /**
     * Function to check if the key exists.
     * @param key String
     */
    public boolean has(String key) {
        return this.valueMap.containsKey(key);
    }

    /**
     * Function to check if the key is empty.
     * @param key type
     */
    public boolean isEmpty(String key) {
        return !this.valueMap.containsKey(key) ||
                this.valueMap.get(key) == null;
    }
}
